package dev.android.yeqh.tvannounce.adapters;

import java.util.ArrayList;
import java.util.List;
import dev.android.yeqh.tvannounce.model.Channel;
import dev.android.yeqh.tvannounce.R;
import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ChannelListAdapter extends BaseAdapter{
	List<Channel> channelList = null;
	Context context = null;
	int layoutId;
	
	public ChannelListAdapter(List<Channel> channelList, Context context, int layoutId) {
		if (channelList == null) {
			this.channelList = new ArrayList<Channel>();
		} else {
			this.channelList = channelList;
		}
		this.context = context;
		this.layoutId = layoutId;
	}
	
	public void setChannels(List<Channel> channelList) {
		if (channelList == null) {
			this.channelList = new ArrayList<Channel>();
		} else {
			this.channelList = channelList;
		}
	}
	
	public String getChannelId(int position) {
		return channelList.get(position).getChannelId();
	}

	public int getCount() {
		return channelList.size();
	}

	public Object getItem(int position) {
		return channelList.get(position);
	}

	public long getItemId(int position) {
		return channelList.get(position).hashCode();
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;
		TextView channelName = null;
		
		view = ((Activity)context).getLayoutInflater().inflate(layoutId, null);
		channelName = (TextView)view.findViewById(R.id.item_channel_name);
		
		channelName.setText(channelList.get(position).getChannelName());
		
		return view;
	}

}
